Skip to content

Conversation

@Allirey
Copy link

@Allirey Allirey commented Oct 23, 2025

This prevents duplicated pvs to stack in the this.currentEval.pvs.

After the movetime in the ceval configuration expires, sometimes (~7%, my estimate) PVs are added again for some reason (perhaps by another worker). This results in this.currentEval.pvs of type [pv1, pv2, pv2, pv3, pv3], and such evals are also cached, for example (positions after random moves):

https://lichess.org/api/cloud-eval?fen=rn1qkb1r/pb3ppp/1p2pn2/2ppN3/5P2/3P2P1/PPP1P1BP/RNBQ1RK1%20b%20kq%20-%201%207&multiPv=3 (1. f4 d5 2. d3 c5 3. Nf3 Nf6 4. g3 b6 5. Bg2 Bb7 6. O-O e6 7. Ne5)
https://lichess.org/api/cloud-eval?fen=rnbqkbnr/pp1ppp1p/2p3p1/8/8/5NP1/PPPPPP1P/RNBQKB1R%20w%20KQkq%20-%200%203&multiPv=5 (1. g3 g6 2. Nf3 c6)

I don't know the root cause of the duplication, maybe someone with a better understanding can suggest a better fix.

@Allirey Allirey marked this pull request as draft October 23, 2025 16:13
@Allirey Allirey marked this pull request as ready for review October 23, 2025 16:34
@schlawg
Copy link
Contributor

schlawg commented Oct 23, 2025

thanks for looking into this!

this area of protocol.ts is indeed kind of broken. in the event Stockfish emits multiple info lines at the same pv and depth within a single search, i think the most recent should be authoritative.

so i recommend something like:

      } else if (this.currentEval) {
        if (this.currentEval.pvs.length < multiPv) this.currentEval.pvs.push(pvData);
        else this.currentEval.pvs[multiPv - 1] = pvData;
        this.currentEval.depth = Math.min(this.currentEval.depth, depth);
      }

@Allirey
Copy link
Author

Allirey commented Oct 24, 2025

so i recommend something like:

      } else if (this.currentEval) {
        if (this.currentEval.pvs.length < multiPv) this.currentEval.pvs.push(pvData);
        else this.currentEval.pvs[multiPv - 1] = pvData;
        this.currentEval.depth = Math.min(this.currentEval.depth, depth);
      }

I would prefer to avoid using multiPv - 1 as an index, your recommendation is similar to my first commit, and I got a different kind of duplication during local testing: pv1 and pv2 (or another pv other than pv1 ) sometimes had the same first move, but slightly different subsequent moves in those pvs. It looks like pv1 should also have changed when overwritten by another worker, but pv1 itself remained old, and pv2 and subsequent ones are overwritten by the index and no longer duplicate each other.

Although I was unable to reproduce such duplication with your recommendation, perhaps this is the fix or duplication of the kind I described above is extremely rare.

@schlawg
Copy link
Contributor

schlawg commented Oct 24, 2025

multiPv - 1 is always the correct index.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants